#include <stdio.h>
#include <stdlib.h>
#include <cstring>
#include <sys/time.h>
#include <iostream>
#include <unistd.h>
#include <pthread.h>

#include "argvparser.h"
#include "fillArgument.h"
#include "ComputationMemory.h"

using namespace std;
using namespace CommandLineProcessing; 

void runTests(int *, pthread_t *, int, char*, char *);


int main(int argc, char * argv[]){
  
  // environement
  Environment * env = new Environment(); 
  ComputationMemory * CMem; 
  // parser for argument. 
  ArgvParser parser; 
  fillArguments(&parser);

  // parse and handle return codes (display help etc...)
  int result = parser.parse(argc, argv);
  if (result != ArgvParser::NoParserError){
    cout << parser.parseErrorDescription(result);
    exit(1);
  }

  // use parser to create the tests environment
  // define size 
  if(parser.foundOption("s")) {
    env->setBlockSize(parser.optionValue("s")); 
  }else {
    env->setBlockSize(B);
  }

  // define thread
  if(parser.foundOption("t")){
    env->setThread(parser.optionValue("t"));
  }else {
    env->setThread("2");
  }

  // define access 
  if (parser.foundOption("a")){
    env->setAccess(parser.optionValue("a"));
  }else {
    env->setAccess(0);
  }  
  // initiate Random
  srand(time(NULL));
    
  CMem = new ComputationMemory(env);

  
  CMem->runTests();

}
